<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>库存盘点</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/common/format/formatDate.js"></script>
<script src="${ctxStatic}/common/change/change.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$(document).on("click","#btnReset",function(){
			$("#cType").val("").select2();
			$("#vaccineId").val("").select2();
			$("#companyCode").val("").select2();
			$("#batchNo").val("");
			$("#beginDate").val("");
			$("#endDate").val("");
		})
		
		initVaccName(stockAndSales.companyCode,stockAndSales.vaccineId);
		initVaccCompanyName(stockAndSales.companyCode);
		$(".vaccineCompany").change(function(){
			var vaccId = $(this).val();
			initCompanyName($(this).val());
			if(vaccId == ""){
				initVaccCompanyName("");
			}
		});
		
		var now = new Date(); //当前日期
		var nowMonth = now.getMonth(); //当前月
        var nowYear = now.getYear(); //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;
        var oldYear = nowYear-1;     //上一年
		$(document).on("click","#month",function(){
			var startDate = new Date($("#beginDate").val());
			startDate.setMonth(startDate.getMonth()-1);
	        var firstDate = getLastMonthFirstDay(startDate);
			var lastDate = getLastMonthLastDay(startDate);
	        $("#beginDate").val(firstDate);
			$("#endDate").val(lastDate);
		})
		$(document).on("click","#thisYear",function(){
			var startDate = new Date($("#beginDate").val());
			var firstDate = getFirstDayOfYear(startDate);
			var lastDate = getLastDayOfYear(startDate);
			$("#beginDate").val(firstDate);
			$("#endDate").val(lastDate);
		})
		$(document).on("click","#thisMonth",function(){
			var firstDate = getThisMonthFirstDay(now);
			var lastDate = getThisMonthNowDay(new Date());
			$("#beginDate").val(firstDate);
			$("#endDate").val(lastDate);
		})
		$(document).on("click","#quarter",function(){
			var startDate = new Date($("#beginDate").val());
			var firstDate = getQuarterFirstDay(startDate);
			var lastDate = getQuarterLastDay(startDate);
			$("#beginDate").val(firstDate);
			$("#endDate").val(lastDate);
		});
		$(document).on("click","#check",function(){
        	debugger;
        	var id = $(this).parent().parent().attr("data-id");
        	var sellPrice = $(this).parent().parent().attr("data-sellPrice")
        	var beginDate = $("#beginDate").val();
        	var endDate = $("#endDate").val();
        	var newDate = $("#newDateOld").val();
        	var url;
        	if(${stockAndSales.storeCode != null}){
        		url = "${ctx }/area/vaccinate/stockAndSalesDetailList?id="+id+"&beginDate="+beginDate+"&endDate="+endDate+"&newDate="+newDate+
        				"&code="+$("#codeId").val()+"&storeCode="+$("#storeCode").val()+"&sellPrice="+sellPrice;
        	}else{
        	    url = "${ctx }/area/vaccinate/stockAndSalesDetailList?id="+id+"&beginDate="+beginDate+"&endDate="
        	    		+endDate+"&newDate="+newDate+"&sellPrice="+sellPrice;
        	}
		    layer.open({
		        type: 2,
		        title: '',
		        shadeClose: true,
		        shade: 0.8,
		        area: [screen.availWidth * 0.7 + 'px', screen.availHeight * 0.6 + 'px' ],
		        content: url 
		      });
        });
		$(document).on("click","#btnView",function(){
			var beginDate = $("#beginDate").val();
        	var endDate = $("#endDate").val();
        	var newDate = $("#newDateOld").val();
			var url = "${ctx }/area/vaccinate/showVacc?vaccineId=" + $("#vaccineId").val()+"&beginDate="+beginDate+
					"&endDate="+endDate+"&newDate="+newDate+"&code="+$("#codeId").val();
		    layer.open({
		        type: 2,
		        title: '',
		        shadeClose: true,
		        shade: 0.8,
		        area: [screen.availWidth*0.6+'px', screen.availHeight*0.6+'px'],
		        content: url 
		     }); 
		});
	});
	
	var stockAndSales = JSON.parse('${fns:toJson(stockAndSales)}');
	
	function down(){
		layer.confirm('确认要导出进销存数据吗？', {
			btn : [ '确认', '取消' ]
		}, function() {
			debugger;
            var beginDate = $("#beginDate").val();
            var endDate = $("#endDate").val();
			$("#searchForm").attr("action", "${ctx}/area/vaccinate/exportExcel");
			$("#searchForm").submit();
			layer.msg('正在导出', {icon: 1});
			$("#searchForm").attr("action", "${ctx}/area/vaccinate/stockAndSalesList");
		}, function() {
			
		});
	}
	function page(n,s){
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
    	return false;
    }
</script>
<style type="text/css">		
	#contentTable td ,#contentTable th{
		text-align: center;
	}
	#contentTable tbody tr td{
		font-size: 13px;
	}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/area/vaccinate/stockAndSalesList">疫苗进销存</a></li>
		<li><a href="${ctx}/expSecondjxc/expVacc">门诊二类苗进销存</a></li>   
	</ul>
	<form:form id="searchForm" modelAttribute="stockAndSales" action="${ctx}/area/vaccinate/stockAndSalesList" method="post" class="breadcrumb form-search ">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="storeCode" name="storeCode" type="hidden" value="${stockAndSales.storeCode}"/>
		<input id="beginDateOld" name="beginDateOld" type="hidden" value="<fmt:formatDate value="${stockAndSales.beginDate}" pattern="yyyy-MM-dd"/>"/>
		<input id="endDateOld" name="endDateOld" type="hidden" value="<fmt:formatDate value="${stockAndSales.endDate}" pattern="yyyy-MM-dd"/>"/>
		<input id="newDateOld" name="newDateOld" type="hidden" value="<fmt:formatDate value="${stockAndSales.newDate}" pattern="yyyy-MM-dd"/>"/>
		<div class="breadcrumb">
			<table class="table table-bordered">
				<tr>
			   	    <th>疫苗类型：</th>
					<td>
						<form:select path="cType" id="cType" class="span2 minWidth">
							<form:option value="" label="--请选择--"/>
							<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select> 
					</td>
					<th>疫苗名称:</th>
					<td>
						<form:select path="vaccineId" id="vaccineId" class="span2 minWidth vaccineCompany" >
						</form:select>
					</td>
				    <th>生产企业:</th>
					<td>
						<form:select path="companyCode" id="companyCode" class="span2 minWidth changeCompany vaccCompanyName" >
						</form:select>
					</td>
				</tr>
				<tr>
					<th>起始日期：</th>
					<td>
						<input id="beginDate" name="beginDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${stockAndSales.beginDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
					</td>
					<th>截止日期：</th>
					<td>
						<input id="endDate" name="endDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${stockAndSales.endDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
					</td>
					<th>疫苗批号：</th>
					<td>
						<form:input path="batchNo" id="batchNo" class="span2 minWidth"/>
					</td>
					<!-- <th>按月/季度/年度统计：</th>
					<td>
						<input type="button" class="btn btn-primary"  id="month"    value="上月"/>
						<input type="button" class="btn btn-primary"  id="thisMonth"    value="本月"/>
						<input type="button" class="btn btn-primary"  id="quarter"  value="本季度"/>
                        <input type="button" class="btn btn-primary"  id="thisYear" value="本年度"/>
					</td> -->
				</tr>
				<tr>
				    <th>地区：</th>
				    <td  colspan="5">
						<sys:treeselect2 id="code" name="code" value="${stockAndSales.code}" labelName="name" labelValue="${stockAndSales.name}"
						title="机构" url="/sys/office/treeData" extId="${office.id}" cssClass="input-medium" allowClear="${office.currentUser.admin}" layer = "true" notAllowSelectParent="true"
						disabled="${office.grade == '50' ? 'disabled' : 'false'}"/>
					</td>
				</tr>
			</table>
		</div>
		<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
		<input id="btnReset" type="button" class="btn btn-primary" value="重置"/>
		<input onclick="down()" class="btn btn-primary" type="button" value="导出"/> 
		<!-- <input id="btnView" class="btn btn-primary" type="button" value="图表显示"/>  -->
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>编号</th>
				<th class="">名称</th>
				<th>属性</th>
				<th>规格</th>
				<th class="w120">生产企业</th>
				<th>批号</th>
				<th>有效期至</th>
				<th>成本价</th>
				<th>出售价</th>
				<th>期初库存</th>
				<th>领取/购进</th>
				<th>下级退回</th>
				<th>下发/售出</th>
				<th>退回上级</th>
				<th>报废</th>
				<th>使用</th>
				<th>报损</th>
				<th>期末库存</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="sas"  begin="0"  varStatus="status">
			<tr data-id="${sas.id}" data-sellPrice ="${sas.sellPrice}">
				<td>
					${(page.pageNo-1)*page.pageSize+status.index+1 }
				</td>
				<td> 
				    <a href="javascript:;" id ="check">${sas.vaccName} </a>
				</td>
				<td>
					${fns:getDictLabel(sas.cType,'bs_vaccine_type','') } 
				</td>
				<c:if test="${sas.batchType == '1' }">
					<td> ${sas.spec} </td>
				</c:if>
				<c:if test="${sas.batchType == '2' }">
					<td>${fns:getDictLabel(sas.spec, 'syringe_spec', '') }</td>
				</c:if>
				<td> ${sas.companyName} </td>
				<td> 
				    ${sas.batchNo}
					<c:if test="${not empty sas.secondBatchno}">
				        <span title="(查询批号时不需要带入亚批号)" style="color:#2fa4e7;">-${sas.secondBatchno}</span>
				    </c:if> 
				</td>
				<td>
					<fmt:formatDate value="${sas.outBoundDate}" pattern="yyyy-MM-dd"/>  
				</td>
				<td style = "text-align: right; padding-right: 10px"> ￥${sas.orignPrice} </td>
				<td style = "text-align: right; padding-right: 10px"> ￥${sas.sellPrice} </td>
				<td> ${sas.histroy} </td>
				<td> ${sas.orderIn} </td>
				<td> ${sas.orderFromReturn} </td>
				<td> ${sas.orderSell} </td>
				<td> ${sas.orderReturn} </td>
				<td> ${sas.orderReject} </td>
				<td> ${sas.orderUse} </td>
				<td> ${sas.orderLoss} </td>
				<td> ${sas.nowPro} </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>